#!/bin/bash

profile_pre_setup() {
  return 0
}



###################################################
#               WITHIN SANDBOX                    #

skel_prepare() {
  return 0
}

skel_base_config() {
  base_apache_setup
  if [[ $? -gt 0 ]] ; then
    return $?
  fi

  base_fcgid_setup
  if [[ $? -gt 0 ]] ; then
    return $?
  fi

  base_php_setup
  if [[ $? -gt 0 ]] ; then
    return $?
  fi

  return 0
}

skel_setup() {
  return 0
}

#                 WITHIN SANDBOX                  #
###################################################




profile_pre_install() {
  return 0
}

profile_install() {
  cd $WORKDIR
  cp -rvfp ./ $VHOST_DIR/

  #chattr -i $FCGIFILE_PATH
  chown $USER:$GROUP -R $VHOST_DIR
  chown root:root -R $CFG_PATH/
  chmod 644 $VHOSTCONFFILE_PATH
  chmod 644 $PHPINIFILE_PATH
  chmod 500 $FCGIFILE_PATH
  chown ${USER}:${GROUP} $FCGIFILE_PATH
  #chattr +i $FCGIFILE_PATH

  # Perhaps ( i am sure) its possible to shorten this and do it better
  LATESTNUM=`find /etc/apache2/vhosts.d/ -name "??_*---vhost.conf" | sed "s/\/etc\/apache2\/vhosts.d\///gi" | sed "s/_.*---vhost\.conf//gi" | sort -nr | head -n1 | sed "s/^0//gi"`;
  let LATESTNUM=$LATESTNUM+1;
  if [ $LATESTNUM -lt 10 ] ; then
  	LATESTNUM="0${LATESTNUM}";
  fi
  SYMLINK="${LATESTNUM}_${DOMAIN}---vhost.conf";
  ln -s "${VHOSTCONFFILE_PATH}" "/etc/apache2/vhosts.d/${SYMLINK}"
  return 0
}

profile_post_install() {
  return 0
}

profile_test() {
  return 0
}

profile_post_setup() {
  return 0
}


